package plugin;

import Phase2.Node;

public class SendMessage implements Visitor 
{
	private Node recipient;
	private Object message;

	@SuppressWarnings("unchecked")
	@Override
	public Object visit(Node n, Object information) throws InterruptedException
	{
		int targetNode;
		if(information instanceof KeyValuePair)
		{
			targetNode = ((KeyValuePair<Integer, Object>) information).getKey();
			message = ((KeyValuePair<Integer, Object>) information).getValue();
		}
		else
		{
			return "Parameter does not contain a KeyValuePair with a Node and Message";
		}
		
		recipient = Node.find(targetNode, n, false);
		recipient.setPayload("message", (String) message);
		
		return information;
	}
}
